package com.pubinfo.passbook.uccp.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.pubinfo.passbook.common.model.bo.uccp.ShortMessageParam;
import com.pubinfo.passbook.common.model.shortMessage.QueryMessageBodyParam;
import com.pubinfo.passbook.common.model.shortMessage.ShortMessageBodyParam;
import com.pubinfo.passbook.uccp.SendSMSService;
import com.ztesoft.uccp.dubbo.interfaces.UCCPSendService;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @author litiewang
 * @version 1.0
 * @date 2021/12/14 16:59
 */
@Service
@Slf4j
public class SendSMSServiceImpl implements SendSMSService {
  
  @Resource
  UCCPSendService uccpSendService;
  
  @SneakyThrows
  @Override
  public String sendShortMessage(ShortMessageParam param) {
  
    ShortMessageBodyParam bodyParam = new ShortMessageBodyParam(param);
    Map reqMap = uccpSendService.sendShortMessage(bodyParam.toMap());
    // return new ShortMessageBodyReply(reqMap);
    String reqStr = JSON.toJSONString(reqMap);
    return reqStr;

  }
  
  @SneakyThrows
  @Override
  public String queryMessage(QueryMessageBodyParam param) {
    Map<String, String> params = JSONObject.parseObject(JSON.toJSONString(param), new TypeReference<Map<String, String>>() {
    });
    Map reqMap = uccpSendService.queryMessage(params);
    String reqStr = JSON.toJSONString(reqMap);
    // return JSONObject.toJavaObject(JSON.parseObject(reqStr), QueryMessageReply.class);
    return reqStr;
  }
}
